import History from './base'

function ensureHash() {
    if(!window.location.hash){
        window.location.hash='/'
    }
}

export default class Hash extends History {
    constructor(router){
        super(router)
         // hash路由初始化的时候 需要增加一个默认hash值 /#/ 
         ensureHash();
    }
    getCurrentLocation(){ //获取当前路由
        return getHash();
    }
    setUpListener(){
        window.addEventListener('hashchange', ()=> {
            // hash变化--切换组件
            this.transitionTo(getHash());
        })
    }
}
function getHash() {
    return window.location.hash.slice(1)
}